home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / list.test < prev    next >
Text File  |  1993-02-06  |  4KB  |  88 lines

  1. # Commands covered:  list
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/list.test,v 1.14 93/02/06 15:54:11 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. # First, a bunch of individual tests
  32.  
  33. test list-1.1 {basic tests} {list a b c} {a b c}
  34. test list-1.2 {basic tests} {list {a b} c} {{a b} c}
  35. test list-1.3 {basic tests} {list \{a b c} {\{a b c}
  36. test list-1.4 {basic tests} "list a{}} b{} c}" "a\\{\\}\\} b{} c\\}"
  37. test list-1.5 {basic tests} {list a\[ b\] } "{a\[} b\\]"
  38. test list-1.6 {basic tests} {list c\  d\t } "{c } {d\t}"
  39. test list-1.7 {basic tests} {list e\n f\$ } "{e\n} {f\$}"
  40. test list-1.8 {basic tests} {list g\; h\\} {{g;} h\\}
  41. test list-1.9 {basic tests} "list a\\\[} b\\\]} " "a\\\[\\\} b\\\]\\\}"
  42. test list-1.10 {basic tests} "list c\\\} d\\t} " "c\\} d\\t\\}"
  43. test list-1.11 {basic tests} "list e\\n} f\\$} " "e\\n\\} f\\$\\}"
  44. test list-1.12 {basic tests} "list g\\;} h\\\\} " "g\\;\\} {h\\}}"
  45. test list-1.13 {basic tests} {list a {{}} b} {a {{}} b}
  46. test list-1.14 {basic tests} {list a b xy\\} "a b xy\\\\"
  47. test list-1.15 {basic tests} "list a b\} e\\" "a b\\} e\\\\"
  48. test list-1.16 {basic tests} "list a b\}\\\$ e\\\$\\" "a b\\}\\\$ e\\\$\\\\"
  49. test list-1.17 {basic tests} {list a\f \{\f} "{a\f} \\\{\\f"
  50. test list-1.18 {basic tests} {list a\r \{\r} "{a\r} \\\{\\r"
  51. test list-1.19 {basic tests} {list a\v \{\v} "{a\v} \\\{\\v"
  52. test list-1.20 {basic tests} {list \"\}\{} "\\\"\\}\\{"
  53. test list-1.21 {basic tests} {list a b c\\\nd} "a b c\\\\\\nd"
  54.  
  55. # For the next round of tests create a list and then pick it apart
  56. # with "index" to make sure that we get back exactly what went in.
  57.  
  58. set num 1
  59. proc lcheck {a b c} {
  60.     global num d
  61.     set d [list $a $b $c]
  62.     test list-2.$num {what goes in must come out} {lindex $d 0} $a
  63.     set num [expr $num+1]
  64.     test list-2.$num {what goes in must come out} {lindex $d 1} $b
  65.     set num [expr $num+1]
  66.     test list-2.$num {what goes in must come out} {lindex $d 2} $c
  67.     set num [expr $num+1]
  68. }
  69. lcheck a b c
  70. lcheck "a b" c\td e\nf
  71. lcheck {{a b}} {} {  }
  72. lcheck \$ \$ab ab\$
  73. lcheck \; \;ab ab\;
  74. lcheck \[ \[ab ab\[
  75. lcheck \\ \\ab ab\\
  76. lcheck {"} {"ab} {ab"}
  77. lcheck {a b} { ab} {ab }
  78. lcheck a{ a{b \{ab
  79. lcheck a} a}b }ab
  80. lcheck a\\} {a \}b} {a \{c}
  81. lcheck xyz \\ 1\\\n2
  82.  
  83. test list-3.1 {error conditions} {catch list msg} 1
  84. test list-3.2 {error conditions} {
  85.     catch list msg
  86.     set msg
  87. } {wrong # args: should be "list arg ?arg ...?"}
  88.